<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2021/10/20
 * Time: 0:19
 */

namespace core\lib;


class HooK
{
    // 注册添加插件
    public static function add($name, $funcName) {
        $GLOBALS['hookList'][$name][] = $funcName;
    }
    // 执行插件
    public static function run($name, $funcName = null, $params = null) {
        if (!class_exists($name)) {
            throw new Exception("class $name not exist");
        }
        foreach ($GLOBALS['hookList'][$name] as $k => $v) {
            $isRun = false;
            if (empty(!$funcName)) {
                if ($funcName == $v) {
                    $isRun = true;
                }
            } else {
                $isRun = true;
            }
            if ($isRun) {
                if (!method_exists(new $name, $v)) {
                    throw new Exception("function $v in class $name not exist");
                }
//                call_user_func([new $name, $v], $params);
                Container::run($name,$v,$params);
            }
        }
    }

}